import { generateExcel } from '@/utils/processExcel'
import { searchFreeGiftOrderExport } from '@/api/store'
import store from '@/store'

const actionsMap = {
    exportFreeGift() {
        const headersConfig = [
            ['姓名', 'customerName'],
            ['电话', 'mobilePhone'],
            // ['地址', 'address'],
            ['申请时间', 'createdAt'],
            ['礼品名称', 'productName'],
            ['礼品描述', 'description']
        ]
        const storeId = store.getters.user_ownedStoreId
        searchFreeGiftOrderExport({ storeId }).then(res => {
            const header = headersConfig.map(item => item[0])
            const resultData = []
            res.forEach(recordItem => {
                resultData.push(headersConfig.map(headerItem => {
                    return recordItem[headerItem[1]] || ''
                }))
            })
            const filename = '免费礼品申请记录'
            generateExcel({ header, filename, data: resultData })
        })
    }
}

export default actionsMap
